package com.library.service;

import java.util.List;

import com.library.common.SPageBean;
import com.library.common.SysUtil;
import com.library.dao.ICommonDAO;
import com.library.model.Bookinfo;

public class AllBookService {
	private ICommonDAO commonDao;

	public ICommonDAO getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(ICommonDAO commonDao) {
		this.commonDao = commonDao;
	}
	public List getAllBooksByPage(SPageBean spb){
		String hql = "from Bookinfo b where b.status="+1;
		commonDao.listByPage(hql, spb);
		return (List)spb.getDatas();
	}
	
	public Bookinfo checkBook(Bookinfo b){
		String hql = "from Bookinfo ";
		
		List<Bookinfo> books = commonDao.list(hql);
		if(books==null||books.size()==0){
			return null;
		}
		return books.get(0);
	}
	
	public List queryBook(SPageBean spb,Bookinfo book){
		/*String hql1 = "from Bookinfo where bookname like '%"+book.getBookname()+"%'";*/
		String hql = "from Bookinfo b where 1 = 1";
		if(SysUtil.isBlankString(book.getBookname())){
			hql += " and b.bookname like '%"+book.getBookname()+"%'";
		}
		if(book.getBookkind()!=0){
			hql += " and b.bookkind="+book.getBookkind();
		}
		commonDao.listByPage(hql, spb);
		return (List)spb.getDatas();
	}
}
